//
//  BLMeTableViewController.m
//  百思不得姐
//
//  Created by hbl on 16/3/14.
//  Copyright © 2016年 hbl. All rights reserved.
//

#import "BLMeTableViewController.h"
#import "BLSettingTableViewController.h"
#import "BLSquare.h"
@interface BLMeTableViewController ()

@end

@implementation BLMeTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNav];
    self.tableView = [[UITableView alloc]initWithFrame:self.tableView.bounds style:UITableViewStyleGrouped];
    self.tableView.sectionFooterHeight = 10;
    self.tableView.sectionHeaderHeight = 0;
    
    UIView *footer = [[BLSquare alloc]init];
    footer.frame = CGRectMake(0, 0, 300, 300);
    self.tableView.tableFooterView = footer;
}

- (void)setupNav
{
    self.navigationItem.title = @"我的";
    UIButton *rightBtn1  = [self setItemButtonWithImage:@"mine-setting-icon" selImage:@"mine-setting-icon-click"];
    [rightBtn1 addTarget:self action:@selector(rightBtn1OnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *rightBtn2 = [self setItemButtonWithImage:@"mine-moon-icon" selImage:@"mine-moon-icon-click"];
     [rightBtn2 addTarget:self action:@selector(rightBtn2OnClick) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.rightBarButtonItems = @[
                        [[UIBarButtonItem alloc]initWithCustomView:rightBtn1],
                        [[UIBarButtonItem alloc]initWithCustomView:rightBtn2]
                                                ];
}

- (UIButton *)setItemButtonWithImage:(NSString *)image selImage:(NSString *)selImage
{
    UIButton *btn = [[UIButton alloc]init];
    [btn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:selImage] forState:UIControlStateHighlighted];
    btn.bounds = CGRectMake(0, 0, btn.currentBackgroundImage.size.width, btn.currentBackgroundImage.size.height);
    
    
    return btn;
}

- (void)rightBtn1OnClick
{
    BLSettingTableViewController *setting = [[BLSettingTableViewController alloc]init];
    [self.navigationController pushViewController:setting animated:YES];
}

- (void)rightBtn2OnClick
{
   
}

#pragma delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    if (indexPath.section == 0) {
        cell.textLabel.text = @"注册/登录";
    }else{
        cell.textLabel.text = @"离线下载";
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
